import {message} from 'antd';
import {formatMessage} from './intl';
export const newOrUpdateOrderValidator = (data, brandId, currency, activityTarget, activityItems) => {
    const requiredFields = [];
    if(!data || !currency)
        requiredFields.push(formatMessage({
            id: 'validator.message.currency',
            defaultMessage: '币种'
        }));
    if(!data || !brandId)
        requiredFields.push(formatMessage({
            id: 'validator.message.brandId',
            defaultMessage: '品牌编号'
        }));
    if(!data || !data.theme)
        requiredFields.push(formatMessage({
            id: 'validator.message.theme',
            defaultMessage: '主题'
        }));
    if(!data || !data.background)
        requiredFields.push(formatMessage({
            id: 'validator.message.background',
            defaultMessage: '背景'
        }));
    if(!data || !data.statDate)
        requiredFields.push(formatMessage({
            id: 'validator.message.statDate',
            defaultMessage: '开始日期'
        }));
    if(!data || !data.endDate)
        requiredFields.push(formatMessage({
            id: 'validator.message.endDate',
            defaultMessage: '结算日期'
        }));
    if(!data || !data.mainItem || data.mainItem.length === 0)
        requiredFields.push(formatMessage({
            id: 'validator.message.mainItem',
            defaultMessage: '主项目'
        }));
    if(data.mainItem && data.mainItem.indexOf(6) !== -1)
        if(!data.mainItemRemark)
            requiredFields.push(formatMessage({
                id: 'validator.message.mainItemRemark',
                defaultMessage: '主项目备注'
            }));
    if(!data || !data.customerQTY)
        requiredFields.push(formatMessage({
            id: 'validator.message.customerQTY',
            defaultMessage: '目标用户量'
        }));
    if(!data || !data.vehicleWarranty)
        requiredFields.push(formatMessage({
            id: 'validator.message.vehicleWarranty',
            defaultMessage: '车辆政策'
        }));
    if(!data || !data.scope)
        requiredFields.push(formatMessage({
            id: 'validator.message.scope',
            defaultMessage: '营销目标'
        }));
    if(!data || !data.marketingProduct)
        requiredFields.push(formatMessage({
            id: 'validator.message.marketingProduct',
            defaultMessage: '营销车型'
        }));
    if(!data || !data.content)
        requiredFields.push(formatMessage({
            id: 'validator.message.content',
            defaultMessage: '营销内容'
        }));
    if(data && activityTarget.length === 0) {
        message.warning(formatMessage({
            id: 'validator.message.activityTarget',
            defaultMessage: '活动预期不能为空!'
        }));
        return false;
    }
    if(data && activityItems.length === 0) {
        message.warning(formatMessage({
            id: 'validator.message.activityItems',
            defaultMessage: '活动项目不能为空!'
        }));
        return false;
    }
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.message.required',
            defaultMessage: '必填!'
        })}`);
        return false;
    }
    return true;
};

export const isEmptyOrNull = value =>
    value === undefined || value === null || value === '';

export const getValidateStatus = (isValidate, value) => {
    if(isValidate) {
        if(isEmptyOrNull(value)) return 'error';
        return null;
    }

    return null;
};

export const approveValidate = data => {
    if(data.approvedResult === null || data.approvedResult === undefined) {
        message.warning(
            formatMessage({
                id: 'validator.approvedResult',
                defaultMessage: '请选择审核结果'
            })
        );
        return false;
    }
    if(data.approveComment === null || data.approveComment === undefined || data.approveComment === '') {
        message.warning(
            formatMessage({
                id: 'validator.approveComment',
                defaultMessage: '请选择审核意见'
            })
        );
        return false;
    }
    return true;
};
